<template>
  <q-layout view="lHh Lpr lFf">
  <q-page-container>
  <q-page class="login-wrap">
    <div class="ms-login">
      <div class="ms-title">电子病历评级数据质量管控平台</div>
      <q-form @submit="submitForm" ref="login" class="ms-content">
        <q-input
          v-model="param.username"
          label="用户名"
          lazy-rules
          :rules="[val => !!val || '请输入用户名']"
        >
          <template v-slot:prepend>
            <q-icon name="person" />
          </template>
        </q-input>
        <q-input
          v-model="param.password"
          type="password"
          label="密码"
          lazy-rules
          :rules="[val => !!val || '请输入密码']"
          @keyup.enter="submitForm"
        >
          <template v-slot:prepend>
            <q-icon name="lock" />
          </template>
        </q-input>
        <div class="login-btn">
          <q-btn type="submit" label="登录" color="primary" />
        </div>
      </q-form>
    </div>
  </q-page>
  </q-page-container>
  </q-layout>
</template>

<script>
export default {
  data() {
    return {
      param: {
        username: 'admin',
        password: '123123'
      }
    }
  },
  methods: {
    submitForm() {
      this.$refs.login.validate().then(success => {
        if (success) {
          let serverHost = 'baota.memlee.top'
          // this.global_request_url.userCheck
          const url = 'http://' + serverHost + ':8999/user_check/'
          const para = {username: this.param.username, password: this.param.password};
          this.$axios.post(url, para).then(resp => {
            const returnData = resp.data;
            if (returnData.code === 'ok') {
              localStorage.setItem('LoginUser', this.param.username);
              this.$q.notify({
                type: 'positive',
                message: '登录成功'
              });
              localStorage.setItem('username', this.param.username)
              this.$router.push('/index');
            } else {
              this.$q.notify({
                type: 'negative',
                message: '请输入正确的账号和密码'
              });
            }
          });
        } else {
          this.$q.notify({
            type: 'negative',
            message: '请输入正确的账号和密码'
          });
        }
      });
    }
  }
}
</script>

<style scoped>
.login-wrap {
  position: relative;
  width: 100%;
  height: 100%;
  background-image: url("http://43.136.220.136:8082/static/img/login-bg2.e213405.jpg");
  background-size: cover;
}

.ms-title {
  width: 100%;
  line-height: 50px;
  text-align: center;
  font-size: 20px;
  color: #fff;
  border-bottom: 1px solid #ddd;
}

.ms-login {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 350px;
  margin: -190px 0 0 -175px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.3);
  overflow: hidden;
}

.ms-content {
  padding: 30px 30px;
}

.login-btn {
  text-align: center;
}

.login-btn .q-btn {
  width: 100%;
  height: 36px;
  margin-bottom: 10px;
}
</style>
